<template>
  <div>
    <h2>随机点名</h2>
    <div class="box">
      <span>名字是：</span>
      <div class="qs">{{name}}</div>
    </div>
    <div class="btns">
      <!-- 设置点击事件 -->
      <button @click="start"  class="start">开始</button>
      <button  @click="over"  class="end">结束</button>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return {
      open:true,
      name:'',
      list :['王昊','顾飞杰','李军仪','郭二炮','国民党']
    }
  },
  methods: {
     move(){
       let num = Math.floor(Math.random()*this.list.length)
     this.name = this.list[num]
     },
    start(){
      if(this.open) {
        this.timer  = setInterval(this.move,100)
        this.open=false
      }
    },
    over() {
      if(!this.open){
        clearInterval(this.timer)
        this.open = true
      }
    }
  }
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

h2 {
  text-align: center;
}

.box {
  width: 600px;
  margin: 50px auto;
  display: flex;
  font-size: 25px;
  line-height: 40px;
}

.qs {
  width: 450px;
  height: 40px;
  color: red;
}

.btns {
  text-align: center;
}

.btns button {
  width: 120px;
  height: 35px;
  margin: 0 50px;
}
</style>